﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Username_DAO
    Public Shared Function KiemTraDuLieu(ByVal NguoiDung As Username_DTO) As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Load Username", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@ursername", NguoiDung.UserName.ToString()))
        cm.Parameters.Add(New SqlParameter("@password", NguoiDung.Password.ToString()))
        Dim data As DataTable = New DataTable()
        Dim data1 As SqlDataAdapter = New SqlDataAdapter()
        data1.SelectCommand = cm
        data1.Fill(data)
        cn.Close()
        Return data
    End Function
    Public Shared Function LayThongTinTaiKhoan() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Load Thong Tin Tai Khoan", cn)
        cm.CommandType = CommandType.StoredProcedure

        Dim data As DataTable = New DataTable()
        Dim data1 As SqlDataAdapter = New SqlDataAdapter()
        data1.SelectCommand = cm
        data1.Fill(data)
        cn.Close()
        Return data
    End Function
    Public Shared Function ThemTaiKhoan(ByVal NguoiDung As Username_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Insert Dang Ky", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@username", NguoiDung.UserName.ToString()))
        cm.Parameters.Add(New SqlParameter("@Password", NguoiDung.PassWord.ToString()))
        Try
            cm.ExecuteNonQuery()
            cn.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function XoaTaiKhoan(ByVal NguoiDung As String) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Xoa Tai Khoan", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@username", NguoiDung.ToString()))
        Try
            cm.ExecuteNonQuery()
            cn.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Shared Function DoiPass(ByVal NguoiDung As Username_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Doi Password", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.Add(New SqlParameter("@username", NguoiDung.UserName.ToString()))
        cm.Parameters.Add(New SqlParameter("@password", NguoiDung.Password.ToString()))
        Try
            cm.ExecuteNonQuery()
            cn.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
End Class
